﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace ConsoleApp
{
    public class demo_webrequest
    {
        public static void demo()
        {
            string url = @"http://192.168.1.101/webapicomment/api/comments";
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            request.Method = "POST";

            string postContent = @"ID=0&Text=Bob&Author=Bob&Email=bob@12&GravatarUrl=11";
            byte[] byteArray = Encoding.UTF8.GetBytes(postContent);
            request.ContentLength = byteArray.Length;
            using (Stream requestStream = request.GetRequestStream())
            {
                requestStream.Write(byteArray, 0, byteArray.Length);
            }

            WebResponse response = request.GetResponse();
            using (Stream reponseStream = response.GetResponseStream())
            {
                StreamReader reader = new StreamReader(reponseStream);
                string responseFromServer = reader.ReadToEnd();
                Console.WriteLine(responseFromServer);
            }
        }
    }
}
